package com.greendizer.api.test.snippets;

import java.util.Date;

import org.junit.Test;

import com.greendizer.api.client.SellerClient;
import com.greendizer.api.resource.seller.Email;
import com.greendizer.api.resource.seller.Seller;
import com.greendizer.api.xmli.CurrencyEnum;
import com.greendizer.api.xmli.Group;
import com.greendizer.api.xmli.Invoice;
import com.greendizer.api.xmli.InvoiceStatusEnum;
import com.greendizer.api.xmli.Line;
import com.greendizer.api.xmli.Tax;
import com.greendizer.api.xmli.XMLNamespace;
import com.greendizer.api.xmli.XMLiBuilder;

public class FirstSnippet {

  @Test
  public void SnippetTest() {
    XMLiBuilder builder = new XMLiBuilder();

    Invoice invoice = new Invoice();
    invoice.setStatus(InvoiceStatusEnum.PAID);
    invoice.setCurrency(CurrencyEnum.USD);
    invoice.setName("Invoice title");
    invoice.setDescription("Invoice description");
    invoice.setDate(new Date());
    invoice.setDueDate(new Date(invoice.getDate().getTime() + 1000 * 60 * 60 * 24 * 30));
    invoice.setTerms("Specific terms and conditions");
    invoice.setBuyerName("Jimi Hendrix");
    invoice.setBuyerEmail("example@domain.com");
    invoice.getBuyerAddress().setStreetAddress("15 rue de Chambéry");
    invoice.getBuyerAddress().setZipcode("75015");
    invoice.getBuyerAddress().setCity("Paris");
    invoice.getBuyerAddress().setCountry("FR");
    builder.addInvoice(invoice);

    Tax vat = new Tax();
    vat.setName("VAT");
    vat.setRate(19.6);

    Group group = new Group();
    group.setName("Group name");
    group.setDescription("Group description");
    invoice.addGroup(group);

    Line line = new Line();
    line.setName("Product or service");
    line.setDescription("Short description");
    line.setQuantity(3);
    line.setUnitPrice(10);
    line.addTax(vat);
    group.addLine(line);

    XMLNamespace namespace = new XMLNamespace("myCompany", "http://www.mycompany.com");
    line.setCustomElement(namespace, "attribute", "value");

    Seller seller = new SellerClient("oauth_token").getUser();
    Email email = seller.getEmails().getById("example@domain.com");
    email.getInvoices().send(builder);
  }
}
